<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>product_isversion.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_useragent_product_isversion.js.html">product_isversion.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2009 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Functions for understanding the version of the browser.
<a name="line17"></a> * This is pulled out of product.js to ensure that only builds that need
<a name="line18"></a> * this functionality actually get it, without having to rely on the compiler
<a name="line19"></a> * to strip out unneeded pieces.
<a name="line20"></a> *
<a name="line21"></a> * TODO(nnaze): Move to more appropriate filename/namespace.
<a name="line22"></a> *
<a name="line23"></a> */
<a name="line24"></a>
<a name="line25"></a>
<a name="line26"></a>goog.provide(&#39;goog.userAgent.product.isVersion&#39;);
<a name="line27"></a>
<a name="line28"></a>
<a name="line29"></a>goog.require(&#39;goog.userAgent.product&#39;);
<a name="line30"></a>
<a name="line31"></a>
<a name="line32"></a>/**
<a name="line33"></a> * @return {string} The string that describes the version number of the user
<a name="line34"></a> *     agent product.  This is a string rather than a number because it may
<a name="line35"></a> *     contain &#39;b&#39;, &#39;a&#39;, and so on.
<a name="line36"></a> * @private
<a name="line37"></a> */
<a name="line38"></a>goog.userAgent.product.determineVersion_ = function() {
<a name="line39"></a>  // All browsers have different ways to detect the version and they all have
<a name="line40"></a>  // different naming schemes.
<a name="line41"></a>
<a name="line42"></a>  if (goog.userAgent.product.FIREFOX) {
<a name="line43"></a>    // Firefox/2.0.0.1 or Firefox/3.5.3
<a name="line44"></a>    return goog.userAgent.product.getFirstRegExpGroup_(/Firefox\/([0-9.]+)/);
<a name="line45"></a>  }
<a name="line46"></a>
<a name="line47"></a>  if (goog.userAgent.product.IE || goog.userAgent.product.OPERA) {
<a name="line48"></a>    return goog.userAgent.VERSION;
<a name="line49"></a>  }
<a name="line50"></a>
<a name="line51"></a>  if (goog.userAgent.product.CHROME) {
<a name="line52"></a>    // Chrome/4.0.223.1
<a name="line53"></a>    return goog.userAgent.product.getFirstRegExpGroup_(/Chrome\/([0-9.]+)/);
<a name="line54"></a>  }
<a name="line55"></a>
<a name="line56"></a>  if (goog.userAgent.product.SAFARI) {
<a name="line57"></a>    // Version/5.0.3
<a name="line58"></a>    //
<a name="line59"></a>    // NOTE: Before version 3, Safari did not report a product version number.
<a name="line60"></a>    // The product version number for these browsers will be the empty string.
<a name="line61"></a>    // They may be differentiated by WebKit version number in goog.userAgent.
<a name="line62"></a>    return goog.userAgent.product.getFirstRegExpGroup_(/Version\/([0-9.]+)/);
<a name="line63"></a>  }
<a name="line64"></a>
<a name="line65"></a>  if (goog.userAgent.product.IPHONE || goog.userAgent.product.IPAD) {
<a name="line66"></a>    // Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1
<a name="line67"></a>    // (KHTML, like Gecko) Version/3.0 Mobile/3A100a Safari/419.3
<a name="line68"></a>    // Version is the browser version, Mobile is the build number. We combine
<a name="line69"></a>    // the version string with the build number: 3.0.3A100a for the example.
<a name="line70"></a>    var arr = goog.userAgent.product.execRegExp_(
<a name="line71"></a>        /Version\/(\S+).*Mobile\/(\S+)/);
<a name="line72"></a>    if (arr) {
<a name="line73"></a>      return arr[1] + &#39;.&#39; + arr[2];
<a name="line74"></a>    }
<a name="line75"></a>  } else if (goog.userAgent.product.ANDROID) {
<a name="line76"></a>    // Mozilla/5.0 (Linux; U; Android 0.5; en-us) AppleWebKit/522+
<a name="line77"></a>    // (KHTML, like Gecko) Safari/419.3
<a name="line78"></a>    //
<a name="line79"></a>    // Mozilla/5.0 (Linux; U; Android 1.0; en-us; dream) AppleWebKit/525.10+
<a name="line80"></a>    // (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2
<a name="line81"></a>    //
<a name="line82"></a>    // Prefer Version number if present, else make do with the OS number
<a name="line83"></a>    var version = goog.userAgent.product.getFirstRegExpGroup_(
<a name="line84"></a>        /Android\s+([0-9.]+)/);
<a name="line85"></a>    if (version) {
<a name="line86"></a>      return version;
<a name="line87"></a>    }
<a name="line88"></a>
<a name="line89"></a>    return goog.userAgent.product.getFirstRegExpGroup_(/Version\/([0-9.]+)/);
<a name="line90"></a>  } else if (goog.userAgent.product.CAMINO) {
<a name="line91"></a>    return goog.userAgent.product.getFirstRegExpGroup_(/Camino\/([0-9.]+)/);
<a name="line92"></a>  }
<a name="line93"></a>
<a name="line94"></a>  return &#39;&#39;;
<a name="line95"></a>};
<a name="line96"></a>
<a name="line97"></a>
<a name="line98"></a>/**
<a name="line99"></a> * Return the first group of the given regex.
<a name="line100"></a> * @param {!RegExp} re Regular expression with at least one group.
<a name="line101"></a> * @return {string} Contents of the first group or an empty string if no match.
<a name="line102"></a> * @private
<a name="line103"></a> */
<a name="line104"></a>goog.userAgent.product.getFirstRegExpGroup_ = function(re) {
<a name="line105"></a>  var arr = goog.userAgent.product.execRegExp_(re);
<a name="line106"></a>  return arr ? arr[1] : &#39;&#39;;
<a name="line107"></a>};
<a name="line108"></a>
<a name="line109"></a>
<a name="line110"></a>/**
<a name="line111"></a> * Run regexp&#39;s exec() on the userAgent string.
<a name="line112"></a> * @param {!RegExp} re Regular expression.
<a name="line113"></a> * @return {Array} A result array, or null for no match.
<a name="line114"></a> * @private
<a name="line115"></a> */
<a name="line116"></a>goog.userAgent.product.execRegExp_ = function(re) {
<a name="line117"></a>  return re.exec(goog.userAgent.getUserAgentString());
<a name="line118"></a>};
<a name="line119"></a>
<a name="line120"></a>
<a name="line121"></a>/**
<a name="line122"></a> * The version of the user agent. This is a string because it might contain
<a name="line123"></a> * &#39;b&#39; (as in beta) as well as multiple dots.
<a name="line124"></a> * @type {string}
<a name="line125"></a> */
<a name="line126"></a>goog.userAgent.product.VERSION = goog.userAgent.product.determineVersion_();
<a name="line127"></a>
<a name="line128"></a>
<a name="line129"></a>/**
<a name="line130"></a> * Whether the user agent product version is higher or the same as the given
<a name="line131"></a> * version.
<a name="line132"></a> *
<a name="line133"></a> * @param {string|number} version The version to check.
<a name="line134"></a> * @return {boolean} Whether the user agent product version is higher or the
<a name="line135"></a> *     same as the given version.
<a name="line136"></a> */
<a name="line137"></a>goog.userAgent.product.isVersion = function(version) {
<a name="line138"></a>  return goog.string.compareVersions(
<a name="line139"></a>      goog.userAgent.product.VERSION, version) &gt;= 0;
<a name="line140"></a>};
</pre>


</body>
</html>
